package br.com.bankai.koby.presentation.security;

import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import br.com.bankai.koby.repository.entity.simple.UsuarioSimple;

/**
 * 
 * @author Leonardo
 *
 */
public class UserInfo extends User {

	private static final long serialVersionUID = -3881281666809405628L;

	private String sourceAddress;

	private UsuarioSimple usuario;

	public UserInfo(String username, String password, Collection<? extends GrantedAuthority> authorities, UsuarioSimple usuario) {
		super(username, password, authorities);
		setUsuario(usuario);
	}

	public String getSourceAddress() {
		return sourceAddress;
	}

	public void setSourceAddress(String sourceAddress) {
		this.sourceAddress = sourceAddress;
	}

	public UsuarioSimple getUsuario() {
		return usuario;
	}

	public void setUsuario(UsuarioSimple usuario) {
		this.usuario = usuario;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((sourceAddress == null) ? 0 : sourceAddress.hashCode());
		result = prime * result + ((usuario == null) ? 0 : usuario.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		UserInfo other = (UserInfo) obj;
		if (sourceAddress == null) {
			if (other.sourceAddress != null)
				return false;
		} else if (!sourceAddress.equals(other.sourceAddress))
			return false;
		if (usuario == null) {
			if (other.usuario != null)
				return false;
		} else if (!usuario.equals(other.usuario))
			return false;
		return true;
	}
}